from rest_framework.viewsets import ModelViewSet
from .models import UserActionLog
from .serializers import UserActionLogSerializer
from .filters import UserActionLogFilter
# class LogView()


class LogView(ModelViewSet):
    queryset = UserActionLog.objects.order_by('-action_time').all()
    serializer_class = UserActionLogSerializer
    filter_class = UserActionLogFilter
    # authentication_classes = []

    def filter_queryset(self, queryset):
        queryset = super().filter_queryset(queryset)
        ids = self.request.user.devices_set.all().values('id')
        print(ids)
        ids = [i['id'] for i in ids]
        if self.request.user.is_superuser:
            return queryset

        return queryset.filter(devices_id__in=ids).all()
